#!/usr/bin/env python
# -*- coding:utf8 -*-
from scrapy.utils.request import request_fingerprint

__all__ = ["RequestHashMiddleware"]


class RequestHashMiddleware(object):
    """
    add request fingerprint to request meta
    """

    def process_request(self, request, spider):
        if not request.meta.get("fingerprint", "") and not request.dont_filter:
            fingerprint = request_fingerprint(request)
            request.meta["fingerprint"] = fingerprint
